local FrameAnimation = class("FrameAnimation",function()
    return display.newNode()
end)

function FrameAnimation:ctor()
    
end

--[[--
--imageNameFormat,startFrameIndex,endFrameIndex,unit
]]
function FrameAnimation:createWidthPlist(parmas)
    local frameAnimation = FrameAnimation.new()
    frameAnimation:initWithPlist(parmas)
    
    return frameAnimation
end

function FrameAnimation:initWithPlist(parmas)
    local frames = display.newFrames(parmas.imageNameFormat, parmas.startFrameIndex, parmas.endFrameIndex)
    self.mAnimation = display.newAnimation(frames, parmas.unit)
    self.mAnimation:retain()
    self.mRunSprite = cc.Sprite:create()
    self:addChild(self.mRunSprite)
    
    self:setNodeEventEnabled(true)
end

function FrameAnimation:onEnter()
    --print("in the FrameAnimation:onEnter")
end

function FrameAnimation:onExit()
    self.mAnimation:release()
    --print("in the FrameAnimation:onExit")
end

--[[--
--@param frameName string 缓存读取需加 ＃ 号
]]
function FrameAnimation:createStaticFrame(frameName)
    self.mStaticFrame = display.newSprite(frameName)
    self:addChild(self.mStaticFrame)
end

function FrameAnimation:showStaticFrame()
    if self.mStaticFrame then
        self.mStaticFrame:setVisible(true)
    end
end

function FrameAnimation:hideStaticFrame()
    if self.mStaticFrame then
        self.mStaticFrame:setVisible(false)
    end
end

function FrameAnimation:runForever()
    self.mRunSprite:playAnimationForever(self.mAnimation)
    self:hideStaticFrame()
end

function FrameAnimation:runOnece()
    self.mRunSprite:playAnimationOnce(self.mAnimation)
    self:hideStaticFrame()
end

function FrameAnimation:stopAnimation()
    self.mRunSprite:stopAllActions()
    self:showStaticFrame()
end

--[[--
--@param pos cc.p 动画坐标
]]
function FrameAnimation:showLocation(pos)
    self.mRunSprite:setPosition(pos)
    if self.mStaticFrame then
        self.mStaticFrame:setPosition(pos)
    end
end

function FrameAnimation:setAnchorPoint(anchor)
    self.mRunSprite:setAnchorPoint(anchor)
    if self.mStaticFrame then
        self.mStaticFrame:setAnchorPoint(anchor)
    end
end

return FrameAnimation